<template>
  <div>
    <!-- <searchper :getperlist.sync="perlist"></searchper> -->
    <el-row style="display:flex;">
      <el-input
        placeholder="人员姓名"
        style="width:20%;margin-right:20px"
        v-model="perData.hash.username"
        clearable
      ></el-input>
      <el-select
        v-model="perData.hash.status"
        placeholder="审核状态"
        style="width:20%;margin-right:20px"
        clearable
      >
        <el-option
          v-for="item in statusoptions"
          :key="item.value"
          :label="item.label"
          :value="item.value"
        ></el-option>
      </el-select>
      <el-input placeholder="获奖内容" style="width:20%" v-model="perData.hash.content" clearable></el-input>
      <el-date-picker
        v-model="perData.hash.grantime"
        style="margin-left:20px;"
        type="daterange"
        rangeSeparator="至"
        startPlaceholder="开始日期"
        endPlaceholder="结束日期"
        valueFormat="yyyy-MM-dd"
        clearable
      ></el-date-picker>
      <el-button style="margin-left:20px;" size="mini" type="primary" @click="getperlist">搜索</el-button>
    </el-row>
    <el-divider></el-divider>
    <el-row>
      <el-button size="mini" @click="showaddper">添加个人业绩</el-button>
      <el-button size="mini" type="primary" @click="amandper">编辑</el-button>
      <el-button size="mini" type="success" @click="deleteper">删除</el-button>
    </el-row>
    <pertable
      :tableData="perlist"
      @itemvals="itemvals"
      :pagobj.sync="pagobj"
      :ischeck="false"
      id="tableExcel"
    ></pertable>

    <addper v-if="isaddper" :itemvalname="itemvalname" :chousebtn="btnvalue" :ismanager="false"></addper>
    <!-- :chouseval="itemvals" -->
  </div>
</template>

<script>
import addper from '~/components/person/performance/addper2.vue';
import pertable from '~/components/person/performance/pertable.vue';
import FileSaver from 'file-saver';
import XLSX from 'xlsx';

export default {
  data() {
    return {
      peridarr: [], // 删除所用的数组id
      isaddper: false, // 添加弹窗
      isaddper2: false, // 编辑弹窗
      btnvalue: 0,
      Object: '',
      itemval: {}, // 编辑传回来的d对象
      id: '',
      dialogVisible: false,
      ts: this.newStore(),
      perData: {
        cols: [],
        hash: {
          username: '',
          content: '',
          grantime: [],
          id: '',
        },
      },
      statusoptions: [
        {
          label: '待审核',
          value: '0',
        },
        {
          label: '审核通过',
          value: '1',
        },
        {
          label: '审核不通过',
          value: '2',
        },
      ],
      pagesize: 0,
      currentPage: 0,
      pagobj: {
        // 分页
        currentPage3: 1,
        pagesize: 10,
        total: 10,
      },
      perlist: [],
      changelistper: {},
    };
  },
  components: {
    addper,
    pertable,
  },
  // watch: {
  //   // Object() {
  //   //   this.getlaborlist();
  //   // },
  //   changelistper() {
  //     this.getperlist();
  //   }
  // },
  created() {
    this.getperlist();
  },
  methods: {
    // 删除个人业绩
    deleteper() {
      // console.log(this.peridarr, "0");
      if (this.peridarr.length > 1) {
        this.$confirm('是否批量删除个人业绩信息?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning',
        }).then(() => {
          const req = {
            handle:
              'D328E4C742B794043F60211ED98E8FE4388F26DA15A6243A479C1A22417B4081',
            id: this.peridarr,
          };
          this.spost(this.ts, '/mainservlet', req).then((ts) => {
            if (ts.d.sflag == 'success') {
              this.$message({
                type: 'success',
                message: '删除成功!',
              });
              this.getperlist();
            }
          });
        });
      } else if (this.peridarr.length == 1) {
        this.$confirm('是否删除该个人业绩信息?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning',
        }).then(() => {
          const req = {
            handle:
              'D328E4C742B794043F60211ED98E8FE4388F26DA15A6243A479C1A22417B4081',
            id: this.peridarr,
          };
          this.spost(this.ts, '/mainservlet', req).then((ts) => {
            if (ts.d.sflag == 'success') {
              this.$message({
                type: 'success',
                message: '删除成功!',
              });
              this.getperlist();
            }
          });
        });
      } else {
        this.$alert('请选择个人业绩', '提示');
      }
    },
    // 编辑个人业绩
    amandper() {
      (this.dialogVisible = true), (this.btnvalue = 2);
      if (Object.keys(this.itemval).length == 1) {
        let itemvals = {};
        itemvals = this.itemval[0];
        this.itemvalname = itemvals;
        // console.log(this.itemvalname,'111111111111')
        this.reload('isaddper');
      } else {
        this.$alert('编辑只能编辑一个', '提示');
      }
    },
    // table 传给父组件
    itemvals(val) {
      // console.log(val, 'wwwwww');
      this.itemval = val;
      this.peridarr = [];
      for (let i = 0; i < this.itemval.length; i++) {
        this.peridarr.push(this.itemval[i].hash.id);
      }
      // console.log(this.peridarr, '23');
    },
    // 监听子组件的(添加)
    addper(val) {
      this.Object = {};
      this.Object = val;
      // val.hash.holder = val.hash.holders;
      // console.log(val, "22223322");
      // this.carlist.unshift(val);
      // console.log(this.perlist, "66666");
    },
    // 公共组件刷新
    reload(partsname) {
      // console.log(partsname);
      this[partsname] = false;
      this.$nextTick(() => {
        this[partsname] = true;
      });
    },
    // 分页
    handleCurrentChange() {
      this.getlaborlist();
    },
    // 点击添加个人业绩信息
    showaddper() {
      (this.dialogVisible = true), (this.btnvalue = 1);
      this.reload('isaddper');
    },
    getperlist() {
      //  console.log("2222");
      if (this.perData.hash.grantime == null) {
        this.perData.hash.grantime = [];
      }
      const req = {
        handle:
          'D328E4C742B794043F60211ED98E8FE473936C62493B31D1F6486B1D96ED9F7E',
        username: this.perData.hash.username,
        content: this.perData.hash.content,
        grantime: this.perData.hash.grantime[0],
        grantimetwo: this.perData.hash.grantime[1],
        status: this.perData.hash.status,
        id: this.perData.hash.id,
        pid: localStorage.getItem('pid'),
        start: (this.pagobj.currentPage3 - 1) * this.pagobj.pagesize,
        limit: this.pagobj.pagesize,
      };
      this.spost(this.ts, '/mainservlet', req).then((ts) => {
        this.perlist = ts.d.data.operation1;
        this.pagobj.total = parseInt(ts.d.data.operation2[0].hash.allrs);
        // console.log(this.perlist,'789')
      });
    }
  },
};
</script>

